import { fundApplyUrl, fundDetailUrl } from '../../../../api/individual'
import { post, get, getMessageAuth } from '../../../../utils/index'

Page({
  data: {
    form: {}
  },
  async loadData () { // 获取申请详情
    const { data } = await get(fundDetailUrl)
    if (data.id) {
      data.img = `../../../../assets/img/${data.fundStatus ? 'checkFail' : 'checking'}_img.png`
      data.title = data.fundStatus ? '办理失败' : '等待处理'
      data.subTitle = data.fundStatus ? data.remark : '已提交审核，等待工作人员处理'
    }
    this.setData({ form: data })
  },
  async submit () { // 申请
    const { form } = this.data
    await post(fundApplyUrl, form)
    this.loadData()
    getMessageAuth()
  },
  edit () { // 重新编辑
    this.setData({ 'form.fundStatus': '' })
  },
  onLoad () {
    this.loadData()
  },
  onPullDownRefresh () {
    const { fundStatus } = this.data.form
    if (fundStatus === 0 || fundStatus === 2) {
      this.loadData()
    }
  }
})